package DAO;
import java.util.Vector;

import DTO.ColInfoDTO;
import DTO.TableDTO;
public class ColInfoDAO {
	private String _DatabasePath;

	public ColInfoDAO(String databasePath) {
		_DatabasePath = databasePath;
	}
	
	public Vector<ColInfoDTO> getAllColInfo(String tableName) throws Exception
	{
		TableDAO tbDAO = new TableDAO(_DatabasePath);
		TableDTO tbDTO = tbDAO.getTable(tableName);
		return tbDTO.get_colInfoList();
	}
	
	public int getColInfoIndex(String tableName, String colName) throws Exception
	{
		Vector<ColInfoDTO> colInfoList = getAllColInfo(tableName);
		for(int i=0; i<colInfoList.size(); i++)
			if(colInfoList.elementAt(i).get_colName().toUpperCase().equals(colName.toUpperCase()))
				return i;
		return -1;
	}
	
	public ColInfoDTO getColInfo(String tableName, int index) throws Exception
	{
		Vector<ColInfoDTO> colInfoList = getAllColInfo(tableName);
		if(index > colInfoList.size())
			return null;
		return colInfoList.elementAt(index);
	}
}
